package org.i1510.common.utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.i1510.common.bean.SessionUserBean;

/**
 * @author Administrator
 * 用户工具
 */
public class UserUtils {
	
	public static SessionUserBean getSessionUserBean(HttpServletRequest request) {
		HttpSession session = request.getSession();
		Object userSession = session.getAttribute("userSession");
		if(null != userSession){
			SessionUserBean rtnVal = (SessionUserBean) userSession;
			return rtnVal;
		}else{
			if(KBProperties.ANONYMOUSUSER_ISUSED){
				SessionUserBean anonymoususer = new SessionUserBean(KBProperties.ANONYMOUSUSER_DOCID,KBProperties.ANONYMOUSUSER_NAME,KBProperties.ANONYMOUSUSER_NICKNAME,request.getSession().getId());
				request.getSession().setAttribute("userSession", anonymoususer);
				return anonymoususer;
			}else{
				return null;
			}
		}
		
	}
}
